/*
 * Copyright (c) 2012-2013, Qualcomm Technologies, Inc.
 * All Rights Reserved.
 * Qualcomm Technologies Proprietary and Confidential.
 */

package com.android.hw.projectmenu;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.service.persistentdata.PersistentDataBlockManager;
import android.util.Log;

public class NetSetting extends PreferenceActivity implements OnPreferenceClickListener {
	
	private static final String KEY_SIMLOCK_STATE = "simlock_state";
	private static final String KEY_QFUSE_STATE = "qfuse_state";
	private static final String KEY_CARRIER_CHECK = "carrier_check";
	private Context mContext = null;
	private String TAG = "NetSetting";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mContext = this;
		addPreferencesFromResource(R.xml.net_setting);
		PreferenceScreen simlockState= (PreferenceScreen) findPreference(KEY_SIMLOCK_STATE);
		simlockState.setOnPreferenceClickListener(this);
		PreferenceScreen qfuseState= (PreferenceScreen) findPreference(KEY_QFUSE_STATE);
		qfuseState.setOnPreferenceClickListener(this);
		PreferenceScreen carrierCheck= (PreferenceScreen) findPreference(KEY_CARRIER_CHECK);
		carrierCheck.setOnPreferenceClickListener(this);
	}

	@Override
	public boolean onPreferenceClick(Preference preference) {
		// TODO Auto-generated method stub
		String key = preference.getKey();
		if (KEY_SIMLOCK_STATE.equals(key)) {
			showDialog(getString(R.string.simlock_state), "RUIM_NW_LOCKED");
		} else if (KEY_QFUSE_STATE.equals(key)) {
			PersistentDataBlockManager dataBlockManager = (PersistentDataBlockManager) getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
			int rootState = dataBlockManager.checkrootornot();
			Log.d(TAG, "rootState="+rootState);
			String rootMsg = "";
			if (rootState == 0) {
				rootMsg = getString(R.string.not_root);
			} else if (rootState == 1) {
				rootMsg = getString(R.string.rooted);
			} else {
				rootMsg = getString(R.string.root_check_error);
			}
			showDialog(getString(R.string.qfuse_state), rootMsg);
		} else if (KEY_CARRIER_CHECK.equals(key)) {
			showDialog(getString(R.string.carrier_check), getString(R.string.carrier_info)+"\n"+getString(R.string.country_info));
		}
		return false;
	}
	
	private void showDialog(String title, String msg) {
		AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
		builder.setTitle(title)
			   .setMessage(msg)
		       .setCancelable(false)
		       .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		        	   
		           }
		       });
		AlertDialog alert = builder.create();
		alert.show();
	}
		       
}
